package mi.payment.ui.admin;

import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.TextView;

import mi.payment.R;
import mi.payment.ui.base.ParentActivity;
import mi.payment.utils.UIUtils;
import sunmi.sunmiui.dialog.DialogCreater;
import sunmi.sunmiui.dialog.HintDialog;
import sunmi.sunmiui.title.Title;

/**
 * 其他管理界面
 * Created by lj on 2017/1/7.
 */
public class OtherSettingsActivity extends ParentActivity {
    private View appRestoreSettingsView, setManagementView,removeTrading,signSinglesPrinting,downloadFunction,parametersPrint;
    private HintDialog mHintDialog;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_system_settings);
        initView();
        setClickListener();
    }

    /**
     * 初始化控件
     */
    private void initView() {
        Title mTitle;
        TextView itemRightText, itemLeftText;
        mTitle = (Title) findViewById(R.id.system_settings_title);
        appRestoreSettingsView = findViewById(R.id.app_restore_settings);
        appRestoreSettingsView.setVisibility(View.GONE);
        setManagementView = findViewById(R.id.set_management);
        removeTrading = findViewById(R.id.remove_trading_water);
        signSinglesPrinting = findViewById(R.id.sign_singles_printing);
        downloadFunction = findViewById(R.id.download_function);
        parametersPrint = findViewById(R.id.parameters_print);

        itemRightText = (TextView) appRestoreSettingsView.findViewById(R.id.item_right_text);
        itemRightText.setVisibility(View.GONE);

        itemRightText = (TextView) setManagementView.findViewById(R.id.item_right_text);
        itemRightText.setVisibility(View.GONE);

        itemRightText = (TextView) removeTrading.findViewById(R.id.item_right_text);
        itemRightText.setVisibility(View.GONE);

        itemRightText = (TextView) signSinglesPrinting.findViewById(R.id.item_right_text);
        itemRightText.setVisibility(View.GONE);

        itemRightText = (TextView) parametersPrint.findViewById(R.id.item_right_text);
        itemRightText.setVisibility(View.GONE);

        itemRightText = (TextView) downloadFunction.findViewById(R.id.item_right_text);
        itemRightText.setVisibility(View.GONE);

        itemLeftText = (TextView) appRestoreSettingsView.findViewById(R.id.item_left_text);
        itemLeftText.setText(getResources().getString(R.string.app_restore_settings));

        itemLeftText = (TextView) setManagementView.findViewById(R.id.item_left_text);
        itemLeftText.setText(getResources().getString(R.string.set_management));

        itemLeftText = (TextView) removeTrading.findViewById(R.id.item_left_text);
        itemLeftText.setText(getResources().getString(R.string.remove_trading_water));

        itemLeftText = (TextView) signSinglesPrinting.findViewById(R.id.item_left_text);
        itemLeftText.setText(getResources().getString(R.string.sign_singles_printing));

        itemLeftText = (TextView) parametersPrint.findViewById(R.id.item_left_text);
        itemLeftText.setText(getResources().getString(R.string.parameters_print));

        itemLeftText = (TextView) downloadFunction.findViewById(R.id.item_left_text);
        itemLeftText.setText(getResources().getString(R.string.download_function));

        mTitle.setButtonVisibility(false, true, true, true);
        mTitle.setHeadBgColor(getResources().getColor(R.color.colorBar));
        mTitle.setTitleText(getResources().getString(R.string.other_management_settings));
        mTitle.setMenuClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OtherSettingsActivity.this.finish();
            }
        }, null, null, null);

    }

    private void setClickListener(){
        appRestoreSettingsView.setOnClickListener(this);
        setManagementView.setOnClickListener(this);
        removeTrading.setOnClickListener(this);
        signSinglesPrinting.setOnClickListener(this);downloadFunction.setOnClickListener(this);
        parametersPrint.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.app_restore_settings:
                //APP还原设置
                showHintDialog();
                break;
            case R.id.set_management:
                //设置管理
                Intent intent = new Intent(Settings.ACTION_SETTINGS);
                startActivity(intent);
                break;
            case R.id.remove_trading_water:
                //清除交易流水
                startActivity(new Intent(this,ClearTradingActivity.class));
                break;
            case R.id.sign_singles_printing:
                //签购单打印
                startActivity(new Intent(this,SalesSlipPrintActivity.class));
                break;
            case R.id.parameters_print:
                //参数打印
                startActivity(new Intent(this,ParamsPrintActivity.class));
                break;
            case R.id.download_function:
                //下载功能
                startActivity(new Intent(this,DownloadManagementActivity.class));
                break;
        }
    }
//    private void clearData(){
//        SystemParamsOperation.getInstance().clearTransactionConfigData();
//        NetworkDataOperations.getInstance().clearNetworkParamSettings();
//        TerminalKeyDataOperations.getInstance().clearTerminalKeyManagementBean();
//    }

    private void showHintDialog(){
        mHintDialog = DialogCreater.createHintDialog(this, R.drawable.state_warning, getResources().getString(R.string.cancel), getResources().getString(R.string.ok), getResources().getString(R.string.ensure_restore), new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mHintDialog.dismiss();
            }
        }, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mHintDialog.dismiss();
            }
        },false);
        mHintDialog.show();
    }
}
